<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="queryParams.projectName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="repositoryList" border>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="仓库名称" align="center" prop="repositoryName" />
      <el-table-column label="主管" align="center" prop="staffName" />
      <el-table-column label="联系方式" align="center" prop="staffPhone" />
      <el-table-column label="库存数量" align="center" prop="quantity" />
      <el-table-column label="库存金额" align="center" prop="amount">
        <template slot-scope="scope">
          <span>{{ toMoney(!scope.row.amount ? 0 : scope.row.amount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="建仓时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleMaterialDdetails(scope.row)"
            v-hasPermi="['cld:projectRepository:materialDdetails']">物资明细</el-button>
          <el-button size="mini" type="text" @click="handleTeamMemberDetails(scope.row)"
            v-hasPermi="['cld:projectRepository:teamMemberDetails']">组员明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 物资明细 -->
    <el-dialog :title="detailsTitle" :visible.sync="detailsOpen" width="80%" append-to-body>
      <material-details v-if="detailsOpen" :form="currRow"></material-details>
    </el-dialog>
  </div>
</template>

<script>
import { listProjectRepository } from "@/api/cld/projectRepository";
import materialDetails from './materialDetails.vue';
export default {
  name: "projectRepository",
  dicts: ['cld_project_region'],
  components: {
    materialDetails
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 项目仓库表格数据
      repositoryList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null
      },
      // 当前选择
      currRow: {},
      detailsTitle: '',
      detailsOpen: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查看项目仓库 */
    getList() {
      this.loading = true;
      listProjectRepository(this.queryParams).then(response => {
        this.repositoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 物资明细
    handleMaterialDdetails(row) {
      this.detailsTitle = '物资明细-' + row.projectName;
      this.currRow = row;
      this.detailsOpen = true;
      // this.$router.push("/projectRepository/material/details/" + row.projectId);
    },
    // 组员明细
    handleTeamMemberDetails(row) {
      this.$router.push("/projectRepository/teamMember/details/" + row.projectId);
    }
  }
};
</script>
<style scoped>
.el-select {
  width: 100%;
}
</style>
